//
//  GuideViewController.m
//  stock
//
//  Created by lq on 15/10/13.
//  Copyright © 2015年 Guangzhou ZhangAoBo Software Technology Co., Ltd. All rights reserved.
//


#import "GuideViewController.h"
#import "GuideCollectionViewCell.h"

@interface GuideViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,strong) NSArray *dataSource;

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
@end


@implementation GuideViewController


static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = HEXColor(@"F0EFF4");
//    self.view.backgroundColor = [UIColor whiteColor];
    self.collectionView.backgroundColor = [UIColor clearColor];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([GuideCollectionViewCell class] ) bundle:nil] forCellWithReuseIdentifier:reuseIdentifier];
    _collectionView.bounces = YES;
    _collectionView.pagingEnabled = YES;
    
    
    NSArray *titls = @[@"便捷的训练记录和排课计划管理",@"关联会员微信，在线约课，课程提醒，查看记录，给客户更好的健身体验",@"认证您的教练身份，官方推荐获得更多客户",@"健身记录分享，朋友圈健身打卡分享，帮助教练提高知名度"];
    NSArray *imageNames = @[@"pic_welcome_yd_02.jpg",@"pic_welcome_yd_03.jpg",@"pic_welcome_yd_04.jpg",@"pic_welcome_yd_05.jpg"];
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0 ; i < imageNames.count; i++) {
        M_GuideModel *model = [[M_GuideModel alloc] init];
        model.title = titls[i];
        model.image = [UIImage imageNamed:imageNames[i]];
        [arr addObject:model];
    }
    _dataSource = arr;
}

- (void)dealloc
{
    NSLog(@"%s",__func__);
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}




- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.pageControl.currentPage = (int)(scrollView.contentOffset.x / kDeviceWidth + 0.5);
    if (scrollView.contentOffset.x > (_dataSource.count-1) * kDeviceWidth) {
        if (self.finishBlock) {
            self.finishBlock();
        }
    }

}
#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _dataSource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    GuideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    M_GuideModel *model = _dataSource[indexPath.row];
    
    cell.guideImageView.image = model.image;
    cell.titleLabel.text = model.title;
    if (indexPath.row == _dataSource.count - 1) {//最后一个
        cell.finishButton.hidden = NO;
        cell.titleLabelTopConstraint.constant = 26;
    } else {
        cell.finishButton.hidden = YES;
        cell.titleLabelTopConstraint.constant = 45;

    }
    if (self.finishBlock) {
        cell.finishBlcok = self.finishBlock;
    }
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
}


@end
@implementation M_GuideModel

@end


